<?php
/**
 * Created by PhpStorm.
 * User: DELL
 * Date: 2018/7/13
 * Time: 16:28
 */
namespace app\common\lib;
class Aes
{
    private $key = null;

    /*
     * @param $key 		密钥
     * @return String
     */
    public function __construct()
    {
        //获取aes key
        $this->key = config('app.aeskey');
    }

    /**
     * 加密
     * @param String input 加密的字符串
     * @param String key   解密的key
     * @return HexString
     */
    public function encrypt($input = '')
    {
        $data = openssl_encrypt($input, 'AES-128-ECB', $this->key, OPENSSL_RAW_DATA);
        $data = base64_encode($data);
        return $data;
    }

    public function decrypt($sStr)
    {
        $decrypted = openssl_decrypt(base64_decode($sStr), 'AES-128-ECB', $this->key, OPENSSL_RAW_DATA);
        return $decrypted;
    }


}